package com.example.controller;

import com.example.common.Result;
import com.example.dto.SubmitRequest;
import com.example.entity.MbtiTestResult;
import com.example.service.MbtiTestService;
import com.example.vo.StudentMBTIResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/mbtitest")
public class MbtiTestController {
    @Resource
    private MbtiTestService mbtiTestService;

    @PostMapping("/submit")
    public Result submitTest(@RequestBody SubmitRequest request) {
        MbtiTestResult result = mbtiTestService.submitTest(request.getUserId(),request.getAnswers());
        return Result.success(result);
    }

    @GetMapping("/history")
    public Result historyTest(@RequestParam Integer userId) {
        List<MbtiTestResult> result = mbtiTestService.historyTest(userId);
        return Result.success(result);
    }

    @GetMapping("/class-mbti")
    public Result getClassStudentMBTIResults(@RequestParam Integer classId) {
        List<StudentMBTIResult> results = mbtiTestService.getClassStudentMBTIResults(classId);
        return Result.success(results);
    }
}
